package com.hr.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hr.entity.PersonalInfo;
import com.hr.service.PersonalInfoService;
import com.hr.utils.ConstantUtil;
import com.hr.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hr
 * @since 2021-10-15
 */
@CrossOrigin
@RestController
@RequestMapping("/hr/service/personal-info")
public class PersonalInfoController {
    @Autowired
    PersonalInfoService personalInfoService;

    @GetMapping("personalInfo")
    public R get_personalInfo() {
        QueryWrapper<PersonalInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", ConstantUtil.CURRENT_USER);
        PersonalInfo personalInfo = personalInfoService.getOne(wrapper);
        return R.ok().data("personalInfo", personalInfo);
    }

    @PostMapping("personalInfo")
    public R add_personalInfo(@RequestBody PersonalInfo personalInfo) {
        personalInfo.setUserId(ConstantUtil.CURRENT_USER);
        boolean save = personalInfoService.save(personalInfo);
        return save ? R.ok() : R.error();
    }

    @PutMapping("personalInfo")
    public R update_personalInfo(@RequestBody PersonalInfo personalInfo) {
        personalInfo.setUserId(ConstantUtil.CURRENT_USER);
        boolean update = personalInfoService.updateById(personalInfo);
        return update ? R.ok() : R.error();
    }
}

